package WWW.SST.LIB;

/** 
 User ��ժҪ˵����
*/
public class UserV2 extends MOLE.App.Every
{
	public int Uid = 0;
	public String uname = "";
	public String upass = "";
	public String email = "";
	public String cp = "";
	public String qq = "";
	public String passQues = "";
	public String passAnswer = "";
	public boolean IsHasPassProtect = false;
	public String tichenbi = "";



	public UserV2(int uid)
	{
		//
		// TODO: �ڴ˴���ӹ��캯���߼�
		//
		Uid = uid;

		String s = "select * from  hy_login_info where hy_num=" + String.valueOf(uid);
		DataTable dd = MOLE.SQL.GetDataTable(s);
		if (dd.Rows.size() > 0)
		{
			uname = dd.Rows[0]["hy_login_name"].toString();
			tichenbi = ((java.math.BigDecimal)(dd.Rows[0]["tichengbili"].toString())).toString("0.00");
		}


		MOLE.SQLOS o = new MOLE.SQLOS("User_FindPwd");
		o.RS(uname);
		DataTable d = o.ExecStoreProcess();
		if (d.Rows.size() > 0)
		{
			Uid = Integer.parseInt(d.Rows[0]["hy_num"].toString());
			passQues = d.Rows[0]["pwdQue"].toString();
			passAnswer = d.Rows[0]["Hy_Pwd_Answer"].toString().trim();
			email = d.Rows[0]["Hy_email"].toString();

			if (passAnswer.equals(""))
			{
				IsHasPassProtect = false;

			}
			else
			{
				IsHasPassProtect = true;
			}
		}
	}

	public UserV2(String name)
	{
		uname = name;
		MOLE.SQLOS o = new MOLE.SQLOS("User_FindPwd");
		o.RS(uname);
		DataTable d = o.ExecStoreProcess();
		if (d.Rows.size() > 0)
		{
			Uid = Integer.parseInt(d.Rows[0]["hy_num"].toString());
			passQues = d.Rows[0]["pwdQue"].toString();
			passAnswer = d.Rows[0]["Hy_Pwd_Answer"].toString().trim();
			email = d.Rows[0]["Hy_email"].toString();
			if (passAnswer.equals(""))
			{
				IsHasPassProtect = false;

			}
			else
			{
				IsHasPassProtect = true;
			}
		}





	}
	public UserV2()
	{

	}

	public final String GetKey()
	{
		int agentId = Uid;
		MOLE.SQLOS o = new MOLE.SQLOS("agentinfo");
		if (o.Exists("aiagentid", agentId))
		{
			DataTable dt = o.GetDataTable("aiagentid", agentId);
			String Key = dt.Rows[0]["aikey"].toString().trim();
			return Key;

		}
		else
		{
			return " ";
		}

	}


	public static DataTable GetAdminList()
	{
		String s = "select * from User_AdminList";
		DataTable d = MOLE.SQL.GetDataTable(s);
		return d;

	}

	public final void Reg()
	{
		//daili_id
		MOLE.SQLOS o = new MOLE.SQLOS("user_reg");
		o.RS(uname);
		o.RS((new LoginEncrypt()).Encrypt(upass));
		o.RS(email);
		o.RS(cp);
		 o.RS(MOLE.GetValue.GetCookieInt("daili_id"));
		o.RS(qq);
		o.RS(MOLE.EncryptDecrypt.MD5(upass).toLowerCase());

		//	o.RS(txtQQ.te
		//o.ExecStoreProcess();

		DataTable d = o.ExecStoreProcess();
		this.StausMsg = d.Rows[0]["result"].toString();
		if (this.StausMsg.toLowerCase().equals("ok"))
		{
			this.StausCode = 0;
		}
		else
		{
			this.StausCode = 1;
		}

	}

	public final void Login(String name, String password)
	{
		String eps = (new LoginEncrypt()).Encrypt(password);
		String s = "select * from hy_login_info where hy_login_name='" + name + "'  and hy_pwd='" + eps + "'";
		DataTable d = MOLE.SQL.GetDataTable(s);
		if (d.Rows.size() == 0)
		{
			this.StausCode = 1;
		}
		else
		{
			this.StausCode = 0;
			 MOLE.Cookie.Set("hy_num", d.Rows[0]["hy_num"].toString().trim(), 1);
			MOLE.Cookie.Set("hy_name", name, 1);
		}


	}

	public final void ResetPwd()
	{
		if (upass.length() < 6)
		{
			this.StausCode = 1;
			this.StausMsg = "���볤�ȱ������6";
			return;
		}


		try
		{
			String pass = (new LoginEncrypt()).Encrypt(upass);

			MOLE.SQLOS o = new MOLE.SQLOS("User_ResetPwc");
			o.RS(Uid);
			o.RS(pass);
			o.ExecStoreProcess();
		}
		catch (RuntimeException ee)
		{
			this.StausCode = 1;
			this.StausMsg = "��������ϵͳ��������";
			this.Log("ee", ee.toString());
		}
	}


	public final void ResetPwdPro(String oldAnswer, String newQ, String newA)
	{

	}
}